Page({
  data: {
    outline: false,
    hidden: false,
    list: [],
    type: '',
    num: '',
    Reason: '',
    kefuphone: '',
    id: '',
    noData: false
  },

  onLoad(query) {
    var that = this;
    that.setData({
      type: JSON.parse(query.data).wlname,
      num: JSON.parse(query.data).wlnumber,
      id: JSON.parse(query.data).id
    })
  },

  onShow() {
    var that = this;
    my.getNetworkType({
      success: (res) => {
        if (res.networkAvailable) {
          that.setData({
            outline: false,
          })
          // 获取token
          my.getStorage({
            key: 'token',
            success: function(res) {
              that.setData({
                token: res.data
              })
            },
            fail: function(res) {
              my.alert({ content: res.errorMessage });
            }
          })
          that.post()
        } else {
          that.setData({
            outline: true
          })
        }
      }
    })
  },
  post() {
    var that = this;
    my.getAuthCode({
      scopes: 'auth_user',
      success: (res) => { //获取用户信息
        my.getAuthUserInfo({
          success: (res) => {
            var req = {
              token: that.data.token,
              id: that.data.id
            }
            my.request({ // 调用自己的服务端接口，让服务端进行后端的授权认证，并且种session，需要解决跨域问题
              url: 'https://www.tiantong369.com/crm/getwl', // 该url是自己的服务地址
              method: 'POST',
              data: req,
              headers: {
                // 'x-access-token': that.data.token
              },
              success: (res) => {
                if (res.data.address.status == 200) {
                  var arr = [];
                  console.log(res.data.address.data.Traces)
                  if (res.data.address.data.Traces.length == 0) {
                    that.setData({
                      Reason: '暂无轨迹信息',
                      noData: true
                    })
                  } else {
                    for (var i = 0; i < res.data.address.data.Traces.length; i++) {
                      arr.push(res.data.address.data.Traces[i])
                    }
                    that.setData({
                      noData: false,
                    })
                  }
                  that.setData({
                    list: arr,
                    kefuphone: res.data.kefuphone,
                    hidden: false,
                  })

                } else {
                  my.showToast({
                    content: '' + res.data.message + '',
                  })
                }
              },
              fail: (res) => {
                console.log('/Wxpay_callback:', res)
              },
            });
          },
        });

      },
    })
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onReady: function() {

  },

  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: 'My App',
      desc: 'My App description',
      path: 'pages/index/index',
    };
  },
})
